package qqclient.view;

import qqclient.service.FileClientService;
import qqclient.service.MessageClientService;
import qqclient.service.UserClientService;
import qqclient.utils.Utility;

public class QQview {

    private boolean loop=true;
    private String key="";
    private UserClientService userClientService=new UserClientService();
    private FileClientService fileClientService=new FileClientService();
    public static void main(String[] args) {
        new QQview().mainMneu();
    }
    private void mainMneu()
    {
        while(loop)
        {
            System.out.println("=====欢迎登录网络通讯系统=====");
            System.out.println("\t\t 1 登陆系统");
            System.out.println("\t\t 9 退出系统");
            System.out.print("请输入你的选择:  ");
            key= Utility.readString(1);
            switch (key) {
                case "1":
                    System.out.println("登录系统");
                    System.out.print("请输入用户号: ");
                    String userId=Utility.readString(50);
                    System.out.print("请输入密码: ");
                    String pwd=Utility.readString(50);
                    //验证用户是否合法
                    if(userClientService.checkUser(userId,pwd))
                    {
                        System.out.println("======欢迎(用户"+userId+")登录成功======");
                        while(loop)
                        {
                            System.out.println("======网络通信系统二级菜单(用户"+userId+")======");
                            System.out.println("\t\t 1 显示在线用户列表");
                            System.out.println("\t\t 2 群发消息");
                            System.out.println("\t\t 3 私聊消息");
                            System.out.println("\t\t 4 发送文件");
                            System.out.println("\t\t 9 退出系统");
                            System.out.print("请输入你的选择:");
                            key = Utility.readString(1);
                            switch (key) {
                                case "1":
                                    System.out.println("显示在线用户列表");
                                    userClientService.onlineFriendList();
                                    break;
                                case "2":
                                    System.out.print("请输入想对大家说的话：");
                                    String s=Utility.readString(100);
                                    MessageClientService.sendMessageToAll(s,userId);
                                    break;
                                case "3":
                                    System.out.print("请输入想在线聊天的用户号：");
                                    String getterId=Utility.readString(50);
                                    System.out.print("请输入像输的话：");
                                    String content=Utility.readString(100);
                                    MessageClientService.sendMessageToOne(content,getterId,userId);
                                    break;
                                case "4":
                                    System.out.print("请输入你想把文件发送给的用户（在线用户）");
                                    getterId=Utility.readString(50);
                                    System.out.print("请输入要发送的文件路径（形式如d:\\xx.jpg）：");
                                    String src=Utility.readString(100);
                                    System.out.print("请输入保存的路径（形式如d:\\xx.jpg）：");
                                    String dest=Utility.readString(100);
                                    fileClientService.sendFileToOne(src,dest,userId,getterId);
                                    break;
                                case "9":
                                    userClientService.logout();
                                    loop = false;
                                    break;
                                default:
                                    System.out.println("输入有误，请重新输入");
                                    break;
                            }
                        }
                    }
                    else
                    {
                        System.out.println("======登录失败======");
                    }
                    break;
                case "9":
                    loop = false;
                    break;

            }
        }
    }

}
